package com.gupaoedu.vip.jdbc.v1;

import java.sql.*;

public class MyJdbcTest {
    public static void main(String[] args) {
        insertUser();
        queryUser();
    }

    private static void insertUser() {
        Connection con;
        Statement stat;
        try {
            con= DriverManager.getConnection("jdbc:mysql://120.78.167.130:3306/mybatis","root","root");
            stat= con.createStatement();
            String sql="insert into t_user(user_name,real_name,password,age,d_id)values('fangjunjie','方俊杰','111',22,1001)";
            stat.executeUpdate(sql);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    private static void queryUser() {
        Connection con;
        Statement stat;
        try {
            con= DriverManager.getConnection("jdbc:mysql://120.78.167.130:3306/mybatis","root","root");
            stat= con.createStatement();
            String sql="select * from t_user";
            ResultSet resultSet =stat.executeQuery(sql);
            while (resultSet.next()){
                System.out.println(resultSet.getString("user_name"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
